package com.deer.wms.kuaidiniao.service.impl;

import com.deer.wms.kuaidiniao.constant.KuaidiniaoConstant;
import com.deer.wms.kuaidiniao.utils.Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class JscxApi {

    //DEMO
    public static void main(String[] args) {
        JscxApi api = new JscxApi();
        try {
            String result = api.getOrderTracesByJson("ANE", "210001633605");
            System.out.print(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Json方式 查询订单物流轨迹
     * @throws Exception
     */
    public String getOrderTracesByJson(String expCode, String expNo) throws Exception{
        String requestData= "{'OrderCode':'','ShipperCode':'" + expCode + "','LogisticCode':'" + expNo + "'}";

        Map<String, String> params = new HashMap<String, String>();
        params.put("RequestData", Utils.urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", KuaidiniaoConstant.EBusinessID);
        params.put("RequestType", "1002");
        String dataSign=Utils.encrypt(requestData, KuaidiniaoConstant.AppKey, "UTF-8");
        params.put("DataSign", Utils.urlEncoder(dataSign, "UTF-8"));
        params.put("DataType", "2");

        String result= Utils.sendPost(KuaidiniaoConstant.JscxReqURL, params);
        return result;
    }
}
